package homework6;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.Statement;

public class Alter {
	public Alter() {
		 try{
		      Class.forName("com.mysql.cj.jdbc.Driver");   
		    }
		    catch (Exception e) {
		      e.printStackTrace();
		    }

	}
	//INSERT INTO `correlation` (`Stu_ID`, `Tea_ID`) VALUES ('201627010120', '001')
	public boolean SalterT(String sID,String tID,String i) {
		boolean s=false;
		try {
	        Connection connect = DriverManager.getConnection(
	            "jdbc:mysql://localhost:3306/student","root","root");
	             //连接URL为   jdbc:mysql//服务器地址/数据库名  ，后面的2个参数分别是登陆用户名和密码
	        //"INSERT INTO teacher VALUES(?,?)"
	        Statement stmt = connect.createStatement();
	        int result = stmt.executeUpdate("update correlation SET Tea_ID="+tID+" where Stu_ID="+sID+" and Tea_ID="+i);
	        if(result==1) {
	        	s=true;
	        }
	        else {
	        	s=false;
	        }
	      }
	    catch (Exception e) {
	       System.out.print("get data error!");
	       e.printStackTrace();
      }
		return s;
	}
	public boolean TalterS(String tID,String PsID,String AsID) {        //PsID表示修改后的sID，AsID表示修改前的sID
		boolean s=false;
		try {
	        Connection connect = DriverManager.getConnection(
	            "jdbc:mysql://localhost:3306/student","root","root");
	             //连接URL为   jdbc:mysql//服务器地址/数据库名  ，后面的2个参数分别是登陆用户名和密码
	        //"INSERT INTO teacher VALUES(?,?)"
	        Statement stmt = connect.createStatement();
	        int result = stmt.executeUpdate("update correlation SET Stu_ID="+PsID+" where Tea_ID="+tID+" and Stu_ID="+AsID);
	        if(result==1) {
	        	s=true;
	        }
	        else {
	        	s=false;
	        }
	      }
	    catch (Exception e) {
	       System.out.print("get data error!");
	       e.printStackTrace();
      }
		return s;
	}
}
